home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / X11 / endo / file.c < prev    next >
C/C++ Source or Header  |  1995-05-03  |  3KB  |  92 lines

  1. /*************************************************************************
  2.  *                                                                       *
  3.  *  Copyright (c) 1992, 1993 Ronald Joe Record                           *
  4.  *                                                                       *
  5.  *  All rights reserved. No part of this program or publication may be   *
  6.  *  reproduced, transmitted, transcribed, stored in a retrieval system,  *
  7.  *  or translated into any language or computer language, in any form or *
  8.  *  by any means, electronic, mechanical, magnetic, optical, chemical,   *
  9.  *  biological, or otherwise, without the prior written permission of:   *
  10.  *                                                                       *
  11.  *      Ronald Joe Record (408) 458-3718                                 *
  12.  *      212 Owen St., Santa Cruz, California 95062 USA                   *
  13.  *                                                                       *
  14.  *************************************************************************/
  15.  
  16. #include <stdio.h>
  17. #include "x.h"
  18.  
  19. /* Store color pics in PPM format and monochrome in PGM */
  20. void
  21. save_to_file(pix, w, h)
  22. Pixmap pix;
  23. int w, h;
  24. {
  25.     FILE *outfile;
  26. /*    FILE *pickfile; */
  27.     unsigned char c;
  28.     XImage *ximage;
  29.     static int i,j;
  30.     struct Colormap {
  31.         unsigned char red;
  32.         unsigned char green;
  33.         unsigned char blue;
  34.     };
  35.     struct Colormap *colormap=NULL;
  36.  
  37.     if (colormap)
  38.         free(colormap);
  39.     if ((colormap=
  40.         (struct Colormap *)malloc(sizeof(struct Colormap)*numcolors))==NULL){
  41.             fprintf(stderr,"Error malloc'ing colormap array.\n");
  42.             Cleanup();
  43.             exit(-1);
  44.         }
  45.     outfile = fopen(outname,"w");
  46. /*    pickfile = fopen("pick.out", "w"); */
  47.     if(!outfile) {
  48.         perror(outname);
  49.         Cleanup();
  50.         exit(-1);
  51.     }
  52.  
  53.     ximage=XGetImage(dpy, pix, 0, 0, w, h, AllPlanes, ZPixmap);
  54.  
  55.     if (displayplanes > 1) {
  56.         for (i=0;i<numcolors;i++) {
  57.             colormap[i].red=(unsigned char)(Colors[i].red >> 8);
  58.             colormap[i].green=(unsigned char)(Colors[i].green >> 8);
  59.             colormap[i].blue =(unsigned char)(Colors[i].blue >> 8);
  60.         }
  61.         fprintf(outfile,"P%d %d %d\n",6,w,h);
  62.     }
  63.     else
  64.         fprintf(outfile,"P%d %d %d\n",5,w,h);
  65.     fprintf(outfile,"# settle=%d  dwell=%d delta=%lf cdelta=%lf\n",
  66.             settle, dwell, delta, cdelt);
  67.     fprintf(outfile,"# min_x=%lf  a_rng=%lf  max_x=%lf\n",min_x,x_range,max_x);
  68.     fprintf(outfile,"# min_y=%lf  b_rng=%lf  max_y=%lf\n",min_y,y_range,max_y);
  69.     for (i=0;i<MAXPARAMS/2;i++)
  70.         fprintf(outfile,"# params[%d]=%lf params[%d]=%lf\n",
  71.                 i,params[i],2*i,params[2*i]);
  72.     fprintf(outfile,"# Map name = %s mapindex=%d\n",
  73.             Mapnames[mapindex], mapindex);
  74.     fprintf(outfile,"# find=%d portrait=%d critical=%d attractors=%d\n",
  75.             find, portrait, critical, attractors);
  76.     fprintf(outfile,"# lyap=%d p1=%d p2=%d start_x=%lf start_y=%lf\n",
  77.             lyap, p1, p2, start_x, start_y);
  78.     fprintf(outfile,"%d\n",numcolors-1);
  79.  
  80.     for (j=0;j<h;j++)
  81.         for (i=0;i<w;i++) {
  82.             c = (unsigned char)XGetPixel(ximage,i,j);
  83.             if (displayplanes > 1)
  84.                 fwrite((char *)&colormap[c],sizeof colormap[0],1,outfile);
  85.             else
  86.                 fwrite((char *)&c,sizeof c,1,outfile);
  87. /*                fwrite((char *)&c,sizeof c,1,pickfile); */
  88.         }
  89.     fclose(outfile);
  90. /*    fclose(pickfile); */
  91. }
  92.